package com.gopay.common.manager.ptbank.impl;

import java.util.List;

import javax.annotation.Resource;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import com.gopay.common.constants.cust.CustCorpInfoConstants;
import com.gopay.common.constants.ptbank.HfSuperviseCode.MERTYPE;
import com.gopay.common.constants.ptbank.HfSuperviseCode.MerNature;
import com.gopay.common.domain.cust.CustCorpInfo;
import com.gopay.common.domain.ptbank.GsrtBankCustSuperviseInfo;
import com.gopay.common.domain.ptbank.invo.PlatAddRequest;
import com.gopay.common.domain.ptbank.invo.PlatModifyRequest;
import com.gopay.common.manager.ptbank.GsrtBankCustSuperviseInfoManager;
import com.gopay.common.manager.ptbank.PtbankPlatManager;
import com.gopay.common.user.manager.CustCorpInfoQueryManager;

/**
 * 商户平台信息
 * PtbankPlatManagerImpl.java
 * 2016年4月26日
 * @author donghuijun
 *  www.gopay.com.cn Inc.All rights reserved.
 */
@Service("ptbankPlatManager")
public class PtbankPlatManagerImpl implements PtbankPlatManager {

	/**
     * 企业用户
     */
    @Resource(name = "custCorpInfoQueryManager")
    private CustCorpInfoQueryManager custCorpInfoQueryManager;
    @Resource(name = "gsrtBankCustSuperviseInfoManager")
    private GsrtBankCustSuperviseInfoManager gsrtBankCustSuperviseInfoManager;
    
    
	
    @Override
    public PlatAddRequest findPlatAddInfo(String merId) {
    	PlatAddRequest platAddRequest = new PlatAddRequest();
    	if(StringUtils.isEmpty(merId)){
    		return null;
    	}
		//查询企业信息
    	CustCorpInfo custCorpInfo = this.custCorpInfoQueryManager.getByCustId(merId);
    	if(null != custCorpInfo){
    		//商户ID
    		platAddRequest.setMerId(custCorpInfo.getCustId());
    		//平台名称
    		platAddRequest.setRegName(custCorpInfo.getCorpName());
    		//注册地址
    		platAddRequest.setRegAddr(custCorpInfo.getCorpAddr());
    		//营业执照编号
    		platAddRequest.setBusiCode(custCorpInfo.getBusinessLicenseNo());
    		//组织机构代码证
    		platAddRequest.setInstuCode(custCorpInfo.getOrganizationCode());
    		//法人姓名
    		platAddRequest.setLegalName(custCorpInfo.getLegalPersonName());
    		//法人证件号码
    		platAddRequest.setLegalCertId(custCorpInfo.getLegalPersonCertNo());
    		//注册资本
    		platAddRequest.setRegFund(custCorpInfo.getRegisteredCapital());
    		//实缴资本
    		//BigDecimal fund = new BigDecimal(0).setScale(2);
//    		platAddRequest.setPaidInfund(custCorpInfo.getPaidInCapital());
    		//企业性质
    		platAddRequest.setMerNature(convertMerNature(custCorpInfo.getCorpType()));
    		//商城地址
    		platAddRequest.setMerWebSite(custCorpInfo.getWebsiteUrl());
    		//平台类型
    		platAddRequest.setMerType(MERTYPE.DEFAULT.value);
    		//日均交易量
    		//BigDecimal averTransVol = new BigDecimal(0).setScale(2);
//    		platAddRequest.setAverTransVol(custCorpInfo.getDailyAvarTradeAmount().toString());
    		//标的产品类型(非必填项)
    		
    	}
		return platAddRequest;
	}
    /**
     * 企业性质码表的转换
     * @param merNature
     * @return
     */
	private String convertMerNature(String merNature){
		if(CustCorpInfoConstants.CORP_TYPE_PRIVATE_ENTERPRISE.equals(merNature)){
			return MerNature.PERSON.value;
		}else if(CustCorpInfoConstants.CORP_TYPE_CORPORATE_ENTERPRISE.equals(merNature)){
			return MerNature.GUFENZHI.value;
		}else if(CustCorpInfoConstants.CORP_TYPE_COLLECTIVE_ENTERPRISE.equals(merNature)){
			return MerNature.HEZI.value;
		}else if(CustCorpInfoConstants.CORP_TYPE_STATE_OWNED_ENTERPRISE.equals(merNature)){
			return MerNature.COUNTORY.value;
		}else if(CustCorpInfoConstants.CORP_TYPE_OVERSEAS_FUNDED_ENTERPRISE.equals(merNature)){
			return MerNature.OTHER.value;
		}else{
			return null;
		}
	}
	@Override
	public PlatModifyRequest findPlatModifyInfo(String merId) {
		PlatModifyRequest platModifyRequest = new PlatModifyRequest();
    	if(StringUtils.isEmpty(merId)){
    		return null;
    	}
		//查询企业信息
    	CustCorpInfo custCorpInfo = this.custCorpInfoQueryManager.getByCustId(merId);
    	//商户银行关系信息
    	List<GsrtBankCustSuperviseInfo> bankCustList = this.gsrtBankCustSuperviseInfoManager.getBankCustSuperviseInfo(merId);
    	
    	if(null != custCorpInfo){
    		//银行平台ID
    		if(!bankCustList.isEmpty()){
    			platModifyRequest.setPlatId(bankCustList.get(0).getPlatId());
    		}
    		//商户ID
    		platModifyRequest.setMerCustId(custCorpInfo.getCustId());
    		//平台名称
    		platModifyRequest.setRegName(custCorpInfo.getCorpName());
    		//注册地址
    		platModifyRequest.setRegAddr(custCorpInfo.getCorpAddr());
    		//营业执照编号
    		platModifyRequest.setBusiCode(custCorpInfo.getBusinessLicenseNo());
    		//组织机构代码证
    		platModifyRequest.setInstuCode(custCorpInfo.getOrganizationCode());
    		//法人姓名
    		platModifyRequest.setLegalName(custCorpInfo.getLegalPersonName());
    		//法人证件号码
    		platModifyRequest.setLegalCertId(custCorpInfo.getLegalPersonCertNo());
    		//注册资本
    		platModifyRequest.setRegFund(custCorpInfo.getRegisteredCapital());
    		//实缴资本
    		//BigDecimal fund = new BigDecimal(0).setScale(2);
//    		platModifyRequest.setPaidInFund(custCorpInfo.getPaidInCapital());
    		//企业性质
    		platModifyRequest.setMerNature(convertMerNature(custCorpInfo.getCorpType()));
    		//商城地址
    		platModifyRequest.setMerWebSite(custCorpInfo.getWebsiteUrl());
    		//平台类型
    		platModifyRequest.setMerType(MERTYPE.DEFAULT.value);
    		//日均交易量
    		//BigDecimal averTransVol = new BigDecimal(0).setScale(2);
//    		platModifyRequest.setAverTransVol(custCorpInfo.getDailyAvarTradeAmount().toString());
    		//标的产品类型(非必填项)
    		
    		//风险控制方式(非必填项)
    	}
		return platModifyRequest;
	}
	@Override
	public PlatAddRequest findPlatDetailInfo(String merId) {
		// TODO Auto-generated method stub
		return null;
	}
}
